package com.huawei.appmarket;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.huawei.appmarket.support.emui.permission.BasePermissionActivity;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;

import java.util.LinkedHashMap;

import o.azb;
import o.cgv;
import o.cjo;
import o.dgh;
import o.dgm;
import o.dgr;
import o.dhn;
import o.dib;
import o.did;
import o.die;
import o.dif;
import o.dig;
import o.dil;
import o.diu;
import o.diw;
import o.djp;
import o.Logger;
import o.doo;
import o.ContentManager;
import o.dqy;
import o.dss;
import o.dsx;
import o.dta.e;
import o.dtc;
import o.dzl;
import o.dzv;
import o.dzw;
import o.eef;
import o.egv;
import o.egx;
import o.egx.d;
import o.ehr;
import o.AccountLoginChecker;
import o.epr;
import o.eqk;
import o.eqm;
import o.esg;
import o.eth;
import o.ActivityUtil;
import o.exw;
import o.ll;


/**
 * 这个就是SplashActivity
 */
public class MainActivity<T extends cjo> extends BasePermissionActivity implements did, dhn, d {
    private View targetView;
    private egx ʼॱ;
    private Handler mHandler = new Handler(this, Looper.getMainLooper()) {
        final /* synthetic */ MainActivity ॱ;

        public void handleMessage(Message message) {
            if (message.what == 1) {
                this.ॱ.targetView.setVisibility(8);
                this.ॱ.ltError.setVisibility(0);
            }
        }
    };
    private long ʿ = 0;
    private BroadcastReceiver ˈ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ MainActivity ˎ;

        {
            this.ˎ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null && this.ˎ != null && !this.ˎ.isFinishing()) {
                String action = intent.getAction();
                if (this.ˎ.getActivityName().equals(intent.getStringExtra(this.ˎ.getActivityName()))) {
                    this.ˎ.setRequestedOrientation(-1);
                    if ("com.huawei.appmarket.startup.flow.end".equals(action)) {
                        Logger.ˎ("GLOBAL_START_FLOW", " FLOW_END ");
                        dzl.ˏ("flowSuccess", this.ˎ.ʿ);
                        dzl.ˏ();
                        this.ˎ.ˎˎ();
                        this.ˎ.ॱˋ();
                        return;
                    } else if ("com.huawei.appmarket.startup.flow.error".equals(action)) {
                        Logger.ˎ("GLOBAL_START_FLOW", " FLOW_ERROR ");
                        this.ˎ.setGone();
                        if (this.ˎ.ltError != null) {
                            Object stringExtra = intent.getStringExtra(HwAccountConstants.EXTRA_OPLOG_ERROR);
                            TextView textView = (TextView) this.ˎ.ltError.findViewById(R.id.title);
                            if (doo.ˊ(context)) {
                                CharSequence string = this.ˎ.getResources().getString(R.string.connect_server_fail_prompt_toast);
                                if (TextUtils.isEmpty(stringExtra)) {
                                    textView.setText(string);
                                } else {
                                    textView.setText(string + "(" + stringExtra + ")");
                                }
                            } else {
                                textView.setText(this.ˎ.getResources().getString(R.string.no_available_network_prompt_title));
                            }
                            this.ˎ.ltError.setVisibility(0);
                            this.ˎ.ᐝॱ = true;
                        }
                        dzl.ˏ();
                        return;
                    } else if ("com.huawei.appmarket.startup.flow.interrupt".equals(action)) {
                        Logger.ˎ("GLOBAL_START_FLOW", " FLOW_INTERRUPT ");
                        dzl.ˏ();
                        dgm.setEnd(dgm.ˎ(this.ˎ));
                        this.ˎ.finish();
                        return;
                    } else {
                        return;
                    }
                }
                Logger.ˎ("MainActivity", "key not equals");
            }
        }
    };
    public die ˊॱ;
    protected long ˏॱ = 0;
    protected TextView tvStartTitle;
    protected View llTitleLayout;
    private View ltError;
    private final BroadcastReceiver ॱᐝ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ MainActivity ॱ;

        {
            this.ॱ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("android.intent.action.LOCALE_CHANGED".equals(intent.getAction())) {
                this.ॱ.finish();
            }
        }
    };
    private boolean ᐝॱ = false;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        Logger.ˎ("GLOBAL_START_FLOW", " onCreate ");
        cgv.ˋ(this, R.color.appgallery_color_appbar_bg, R.color.emui_white);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.emui_white));
        ͺ();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.LOCALE_CHANGED");
        ActivityUtil.registerReceiver(this, intentFilter, this.ॱᐝ);
        ActivityUtil.ˏ(true);
        ᐝ();
        ehr.ˏ().ˊ();
    }

    protected void ᐝ() {
        exw.ˎ((Context) this, "gallery");
    }

    public void ͺ() {
        epr.ˎ().ˎ(null);
    }

    public String getActivityName() {
        return "MainActivity";
    }

    public void ॱˊ() {
        boolean booleanExtra = new SafeIntent(getIntent()).getBooleanExtra("from_restart", false);
        Logger.ˎ("MainActivity", " fromRestart = " + booleanExtra);
        if (booleanExtra) {
            ˊ(false);
        } else if (!this.ˊॱ.ˊ()) {
            ˊ(false);
        }
    }

    private void ʽॱ() {
        Logger.ˎ("GLOBAL_START_FLOW", " registerBroadcast ");
        ll ˏ = ll.ˏ(ContentManager.getInstant().getContext());
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.startup.flow.interrupt");
        intentFilter.addAction("com.huawei.appmarket.startup.flow.end");
        intentFilter.addAction("com.huawei.appmarket.startup.flow.error");
        ˏ.ˏ(this.ˈ, intentFilter);
    }

    private void ˈ() {
        Logger.ˎ("GLOBAL_START_FLOW", " unregisterBroadcast ");
        ll.ˏ(getApplicationContext()).ˋ(this.ˈ);
        if (this.ॱᐝ != null) {
            ActivityUtil.unregisterReceiver((Context) this, this.ॱᐝ);
        }
    }

    public void ॱॱ() {
        diw.ˋ();
        esg.ˋ().ˊ(dgm.ˎ((Activity) this));
        this.ʼॱ = new egx(this);
        ʽॱ();
        dib o_dib = (dib) ab_();
        if (o_dib == null) {
            this.ˊॱ = new die(this);
        } else {
            this.ˊॱ = new die(this, o_dib.ॱ(), o_dib.ˊ());
        }
        dsx.ˏ(e.GET_ALL_DATA);
        dtc.ˋ(0);
        ˏ(8);
        ˊˊ();
        if (dqy.ˋ()) {
            dzv.ˊ();
            finish();
            return;
        }
        ˊᐝ();
    }

    public void ˏ(int i) {
        if (this.llTitleLayout != null) {
            this.llTitleLayout.setVisibility(i);
        }
    }

    public void setStartTitle() {
        if (this.tvStartTitle != null) {
            this.tvStartTitle.setText(getResources().getString(R.string.client_app_name));
        }
    }

    public void ʼ() {
        setContentView(R.layout.activity_main);
        this.ltError = findViewById(R.id.error_layout);
        this.targetView = findViewById(R.id.loading_layout);
        this.llTitleLayout = findViewById(R.id.hiapp_start_title_linearlayout);
        azb.ˏ(this.llTitleLayout);
        this.tvStartTitle = (TextView) this.llTitleLayout.findViewById(R.id.start_title);
        setStartTitle();
    }

    private void ˊᐝ() {
        Object obj = 1;
        Object obj2 = (this.ˊॱ == null || TextUtils.isEmpty(this.ˊॱ.ॱ)) ? null : 1;
        if (obj2 != null) {
            ˎˎ();
            return;
        }
        if (diu.ˊ().ˎ()) {
            eqm ˊ = eqk.ˊ();
            if (ˊ == null || !ˊ.ॱ()) {
                obj = null;
            }
            if (obj != null) {
                Logger.ˎ("GLOBAL_START_FLOW", "grs homeCountryChange");
                ˊˋ();
            } else {
                Logger.ˎ("GLOBAL_START_FLOW", "not first startup");
                if (!ˋˊ()) {
                    ˎˎ();
                } else {
                    return;
                }
            }
            ॱˋ();
        } else {
            ˊˋ();
        }
        this.ˏॱ = System.currentTimeMillis();
    }

    private boolean ˋˊ() {
        if (!this.ᐝॱ) {
            return false;
        }
        ˉ();
        ˏ(0);
        return true;
    }

    public void ॱˋ() {
        if (dgr.ˋ().ॱ("desktop")) {
            int ˎ = dgm.ˎ((Activity) this);
            LinkedHashMap linkedHashMap = new LinkedHashMap(2);
            linkedHashMap.put("start_type", "desktop");
            linkedHashMap.put("service_type", Integer.valueOf(ˎ));
            dgh.ˋ("action_start_by_type", linkedHashMap);
            dgr.ˋ().ˋ("desktop|" + ˎ, ˎ);
        }
    }

    private void ˊˋ() {
        //条款流程
        Logger.ˎ("GLOBAL_START_FLOW", "first startup");
        setVisible();
        if (!(dgm.ˎ((Activity) this) == 17 || dgm.ˎ((Activity) this) == 18)) {
            diu.ˊ().ˏ();
        }
        this.ʿ = dgh.ॱ();
        dzl.ˋ();
        dzw.ॱ((Activity) this, getActivityName());
    }

    private void ˊˊ() {
        ((ImageView) this.ltError.findViewById(R.id.no_wifi)).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ MainActivity ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(View view) {
                if (doo.ˊ(ContentManager.getInstant().getContext())) {
                    this.ॱ.ᐝॱ = false;
                    this.ॱ.ltError.setVisibility(8);
                    this.ॱ.ˊᐝ();
                    return;
                }
                this.ॱ.ˉ();
            }
        });
        this.ltError.findViewById(R.id.setting).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ MainActivity ˏ;

            {
                this.ˏ = r1;
            }

            public void onClick(View view) {
                eth.ˊ(this.ˏ);
            }
        });
        this.ltError.findViewById(R.id.go_to_net_diagnose).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ MainActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(View view) {
                eth.ॱ(this.ˊ);
            }
        });
    }

    public Object T_() {
        dib o_dib = new dib();
        if (this.ˊॱ != null) {
            o_dib.ˎ(this.ˊॱ.ˏ());
            o_dib.ˋ(this.ˊॱ.ॱ);
        }
        return o_dib;
    }

    protected void ˊ(boolean z) {
        Logger.ˎ("GLOBAL_START_FLOW", " startMainFrameAndFinish ");
        djp.ˎ().ˋ(false);
        dig.ˏ();
        Intent intent = new Intent(this, MarketActivity.class);
        intent.putExtra("isfromonkeydown", z);
        startActivity(intent);
        finish();
    }

    public void onResume() {
        super.onResume();
        if (this.ˏॱ > 0 && System.currentTimeMillis() - this.ˏॱ > 2000) {
            this.ˏॱ = System.currentTimeMillis();
            if (this.ltError != null && this.ltError.getVisibility() == 0) {
                if (doo.ˊ(ContentManager.getInstant().getContext())) {
                    this.ᐝॱ = false;
                    this.ltError.setVisibility(8);
                    ˊᐝ();
                    return;
                }
                ˉ();
            }
        }
    }

    private void ˉ() {
        if (this.ltError != null && this.targetView != null) {
            this.ltError.setVisibility(8);
            this.targetView.setVisibility(0);
            this.mHandler.sendMessageDelayed(this.mHandler.obtainMessage(1), 500);
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        if (bundle != null) {
            bundle.putBoolean("global_flow_error", this.ᐝॱ);
            super.onSaveInstanceState(bundle);
        }
    }

    public void ˎ(Bundle bundle) {
        super.ˎ(bundle);
        if (bundle != null) {
            this.ᐝॱ = bundle.getBoolean("global_flow_error", false);
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.ʼॱ != null) {
            this.ʼॱ.ˋ();
            this.ʼॱ = null;
        }
        diu.ˊ().ˋ(this);
        ˈ();
    }

    private void ˎˎ() {
        if (!egv.ॱᐝ().ͺ()) {
            egv.ॱᐝ().ˏ(false);
            ॱˊ();
        } else if (this.ʼॱ != null) {
            this.ʼॱ.ˋ(this, "home_country_change");
        }
    }

    @Override
    public void ʻॱ() {

    }

    public void ॱ(String str) {
        boolean equals = "zjbbapps".equals(str);
        if (equals) {
            if (dil.ˏ().ˋ()) {
                dss.ॱ().ˋ(dil.ˏ().ˎ());
            }
            if (dil.ˏ().ˊ()) {
                new eef().ˏ(dil.ˏ().ʽ());
            }
        }
        dif ˎ = this.ˊॱ.ˎ(str);
        Object obj = null;
        if (ˎ != null && ˎ.ॱ()) {
            obj = 1;
        }
        this.ˊॱ.ˏ(str);
        if (obj != null || !this.ˊॱ.ॱ()) {
            ˊ(equals);
        } else if (this.ˊॱ.ॱ() && !this.ˊॱ.ˊ()) {
            ˊ(equals);
        }
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        Logger.ˎ("MainActivity", "onkey back main");
        if (i != 4 || this.ˊॱ == null || !this.ˊॱ.ˎ()) {
            return super.onKeyDown(i, keyEvent);
        }
        ˊ("zjbbapps".equals(this.ˊॱ.ॱ));
        dil.ˏ().ˋ(this);
        if ("zjbbapps".equals(this.ˊॱ.ॱ) && dil.ˏ().ˊ()) {
            new eef().ˏ(dil.ˏ().ʽ());
        }
        return true;
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        AccountLoginChecker.ˏ().ˊ(i, i2, intent);
        if (1002 == i) {
            ॱ("zjbbapps");
        }
    }

    public void targetView() {
        ˊ(false);
    }

    private void setVisible() {
        if (this.targetView != null) {
            this.targetView.setVisibility(View.VISIBLE);
        }
    }

    private void setGone() {
        if (this.targetView != null) {
            this.targetView.setVisibility(View.GONE);
        }
    }

    public void finish() {
        super.finish();
        dzl.ˏ();
    }

    public void ॱˎ() {
        egv.ॱᐝ().ˏ(false);
        ॱˊ();
    }
}
